{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a81cae22-6b75-436c-a59b-153936573662",
   "metadata": {},
   "outputs": [],
   "source": [
    "#导入pyecharts\n",
    "from pyecharts.charts import Sunburst\n",
    "from pyecharts.charts import TreeMap\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.globals import ThemeType\n",
    "\n",
    "#在jupyter notebook演示\n",
    "from pyecharts.globals import CurrentConfig, NotebookType \n",
    "CurrentConfig.NOTEBOOK_TYPE = NotebookType.NTERACT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a5ff2d08-9894-4fb3-9777-30f081f5260c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html>\n",
       "<html>\n",
       "<head>\n",
       "    <meta charset=\"UTF-8\">\n",
       "    <title>Awesome-pyecharts</title>\n",
       "            <script type=\"text/javascript\" src=\"https://assets.pyecharts.org/assets/echarts.min.js\"></script>\n",
       "        <script type=\"text/javascript\" src=\"https://assets.pyecharts.org/assets/themes/roma.js\"></script>\n",
       "\n",
       "</head>\n",
       "<body>\n",
       "    <div id=\"578596b84f744d1f88738fe80ab4ced3\" class=\"chart-container\" style=\"width:1500px; height:800px;\"></div>\n",
       "    <script>\n",
       "        var chart_578596b84f744d1f88738fe80ab4ced3 = echarts.init(\n",
       "            document.getElementById('578596b84f744d1f88738fe80ab4ced3'), 'roma', {renderer: 'canvas'});\n",
       "        var option_578596b84f744d1f88738fe80ab4ced3 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"sunburst\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"itemStyle\": {\n",
       "                        \"color\": \"#2a1188\"\n",
       "                    },\n",
       "                    \"children\": [\n",
       "                        {\n",
       "                            \"name\": \"\\u5e7f\\u5dde\",\n",
       "                            \"value\": 2762\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6df1\\u5733\",\n",
       "                            \"value\": 2511\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e1c\\u839e\",\n",
       "                            \"value\": 494\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4f5b\\u5c71\",\n",
       "                            \"value\": 368\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e2d\\u5c71\",\n",
       "                            \"value\": 123\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u73e0\\u6d77\",\n",
       "                            \"value\": 347\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6c5f\\u95e8\",\n",
       "                            \"value\": 106\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u60e0\\u5dde\",\n",
       "                            \"value\": 108\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6e5b\\u6c5f\",\n",
       "                            \"value\": 56\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u9633\\u6c5f\",\n",
       "                            \"value\": 52\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u8087\\u5e86\",\n",
       "                            \"value\": 55\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u8302\\u540d\",\n",
       "                            \"value\": 24\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e91\\u6d6e\",\n",
       "                            \"value\": 7\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6e05\\u8fdc\",\n",
       "                            \"value\": 23\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u97f6\\u5173\",\n",
       "                            \"value\": 12\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6cb3\\u6e90\",\n",
       "                            \"value\": 7\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6c55\\u5c3e\",\n",
       "                            \"value\": 13\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u63ed\\u9633\",\n",
       "                            \"value\": 11\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6c55\\u5934\",\n",
       "                            \"value\": 27\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6885\\u5dde\",\n",
       "                            \"value\": 19\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6f6e\\u5dde\",\n",
       "                            \"value\": 7\n",
       "                        }\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"itemStyle\": {\n",
       "                        \"color\": \"#da1bb0\"\n",
       "                    },\n",
       "                    \"children\": [\n",
       "                        {\n",
       "                            \"name\": \"\\u671d\\u9633\",\n",
       "                            \"value\": 377\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6d77\\u6dc0\",\n",
       "                            \"value\": 135\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e30\\u53f0\",\n",
       "                            \"value\": 401\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5927\\u5174\",\n",
       "                            \"value\": 157\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u623f\\u5c71\",\n",
       "                            \"value\": 151\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u77f3\\u666f\\u5c71\",\n",
       "                            \"value\": 27\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u901a\\u5dde\",\n",
       "                            \"value\": 80\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u660c\\u5e73\",\n",
       "                            \"value\": 81\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u987a\\u4e49\",\n",
       "                            \"value\": 78\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u897f\\u57ce\",\n",
       "                            \"value\": 70\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e1c\\u57ce\",\n",
       "                            \"value\": 49\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u95e8\\u5934\\u6c9f\",\n",
       "                            \"value\": 8\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5ef6\\u5e86\",\n",
       "                            \"value\": 2\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6000\\u67d4\",\n",
       "                            \"value\": 8\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5bc6\\u4e91\",\n",
       "                            \"value\": 9\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5e73\\u8c37\",\n",
       "                            \"value\": 0\n",
       "                        }\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"itemStyle\": {\n",
       "                        \"color\": \"#901215\"\n",
       "                    },\n",
       "                    \"children\": [\n",
       "                        {\n",
       "                            \"name\": \"\\u6d66\\u4e1c\",\n",
       "                            \"value\": 16820\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u9ec4\\u6d66\",\n",
       "                            \"value\": 6222\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5f90\\u6c47\",\n",
       "                            \"value\": 4515\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u9759\\u5b89\",\n",
       "                            \"value\": 2907\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u8679\\u53e3\",\n",
       "                            \"value\": 3380\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u95f5\\u884c\",\n",
       "                            \"value\": 5259\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6768\\u6d66\",\n",
       "                            \"value\": 1880\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5b9d\\u5c71\",\n",
       "                            \"value\": 2832\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u957f\\u5b81\",\n",
       "                            \"value\": 2377\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u666e\\u9640\",\n",
       "                            \"value\": 1737\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u9752\\u6d66\",\n",
       "                            \"value\": 1287\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5d07\\u660e\",\n",
       "                            \"value\": 383\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u677e\\u6c5f\",\n",
       "                            \"value\": 2887\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5949\\u8d24\",\n",
       "                            \"value\": 230\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5609\\u5b9a\",\n",
       "                            \"value\": 2361\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u91d1\\u5c71\",\n",
       "                            \"value\": 332\n",
       "                        }\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                0,\n",
       "                \"95\"\n",
       "            ],\n",
       "            \"highlightPolicy\": \"descendant\",\n",
       "            \"nodeClick\": \"rootToNode\",\n",
       "            \"sort\": \"null\",\n",
       "            \"levels\": [\n",
       "                {},\n",
       "                {\n",
       "                    \"r0\": \"15%\",\n",
       "                    \"r\": \"35%\",\n",
       "                    \"itemStyle\": {\n",
       "                        \"borderWidth\": 2\n",
       "                    },\n",
       "                    \"label\": {\n",
       "                        \"rotate\": \"tangential\"\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"r0\": \"35%\",\n",
       "                    \"r\": \"70%\",\n",
       "                    \"label\": {\n",
       "                        \"align\": \"right\"\n",
       "                    }\n",
       "                }\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u65b0\\u51a0\\u7d2f\\u8ba1\\u786e\\u8bca\\u75c5\\u4f8b \\u65ed\\u65e5\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "        chart_578596b84f744d1f88738fe80ab4ced3.setOption(option_578596b84f744d1f88738fe80ab4ced3);\n",
       "    </script>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7fcb09466460>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 新冠累计确诊\n",
    "data = [\n",
    "    {\"name\": \"广东\",\n",
    "     \"itemStyle\": {\"color\": \"#2a1188\"},\n",
    "     \"children\": [\n",
    "             {\"name\": \"广州\", \"value\": 2762},\n",
    "             {\"name\": \"深圳\", \"value\": 2511},\n",
    "             {\"name\": \"东莞\", \"value\": 494},\n",
    "             {\"name\": \"佛山\", \"value\": 368},\n",
    "             {\"name\": \"中山\", \"value\": 123},\n",
    "             {\"name\": \"珠海\", \"value\": 347},\n",
    "             {\"name\": \"江门\", \"value\": 106},\n",
    "             {\"name\": \"惠州\", \"value\": 108},\n",
    "             {\"name\": \"湛江\", \"value\": 56},\n",
    "             {\"name\": \"阳江\", \"value\": 52},\n",
    "             {\"name\": \"肇庆\", \"value\": 55},\n",
    "             {\"name\": \"茂名\", \"value\": 24},\n",
    "             {\"name\": \"云浮\", \"value\": 7},\n",
    "             {\"name\": \"清远\", \"value\": 23},\n",
    "             {\"name\": \"韶关\", \"value\": 12},\n",
    "             {\"name\": \"河源\", \"value\": 7},\n",
    "             {\"name\": \"汕尾\", \"value\": 13},\n",
    "             {\"name\": \"揭阳\", \"value\": 11},\n",
    "             {\"name\": \"汕头\", \"value\": 27},\n",
    "             {\"name\": \"梅州\", \"value\": 19},\n",
    "             {\"name\": \"潮州\", \"value\": 7}   \n",
    "     ],\n",
    "     },\n",
    "    {\"name\": \"北京\",\n",
    "     \"itemStyle\": {\"color\": \"#da1bb0\"},\n",
    "     \"children\": [\n",
    "             {\"name\": \"朝阳\", \"value\": 377},\n",
    "             {\"name\": \"海淀\", \"value\": 135},\n",
    "             {\"name\": \"丰台\", \"value\": 401},\n",
    "             {\"name\": \"大兴\", \"value\": 157},\n",
    "             {\"name\": \"房山\", \"value\": 151},\n",
    "             {\"name\": \"石景山\", \"value\": 27},\n",
    "             {\"name\": \"通州\", \"value\": 80},\n",
    "             {\"name\": \"昌平\", \"value\": 81},\n",
    "             {\"name\": \"顺义\", \"value\": 78},\n",
    "             {\"name\": \"西城\", \"value\": 70},\n",
    "             {\"name\": \"东城\", \"value\": 49},\n",
    "             {\"name\": \"门头沟\", \"value\": 8},\n",
    "             {\"name\": \"延庆\", \"value\": 2},\n",
    "             {\"name\": \"怀柔\", \"value\": 8},\n",
    "             {\"name\": \"密云\", \"value\": 9},\n",
    "             {\"name\": \"平谷\", \"value\": 0},\n",
    "     ],\n",
    "     },\n",
    "    {\"name\": \"上海\", \n",
    "     \"itemStyle\": {\"color\": \"#901215\"},\n",
    "     \"children\": [\n",
    "             {\"name\": \"浦东\", \"value\": 16820},\n",
    "             {\"name\": \"黄浦\", \"value\": 6222},\n",
    "             {\"name\": \"徐汇\", \"value\": 4515},\n",
    "             {\"name\": \"静安\", \"value\": 2907},\n",
    "             {\"name\": \"虹口\", \"value\": 3380},\n",
    "             {\"name\": \"闵行\", \"value\": 5259},\n",
    "             {\"name\": \"杨浦\", \"value\": 1880},\n",
    "             {\"name\": \"宝山\", \"value\": 2832},\n",
    "             {\"name\": \"长宁\", \"value\": 2377},\n",
    "             {\"name\": \"普陀\", \"value\": 1737},\n",
    "             {\"name\": \"青浦\", \"value\": 1287},\n",
    "             {\"name\": \"崇明\", \"value\": 383},\n",
    "             {\"name\": \"松江\", \"value\": 2887},\n",
    "             {\"name\": \"奉贤\", \"value\": 230},\n",
    "             {\"name\": \"嘉定\", \"value\": 2361},\n",
    "             {\"name\": \"金山\", \"value\": 332},\n",
    "     ],\n",
    "     },\n",
    "]\n",
    "\n",
    "\n",
    "sunburst = (\n",
    "    Sunburst(init_opts = opts.InitOpts(width = \"1500px\",height = \"800px\",theme = ThemeType.ROMA))\n",
    "    .add(\n",
    "        \"\", \n",
    "        data_pair = data,\n",
    "        radius = [0,\"95\"],#弧形弯度\n",
    "        sort_ = \"null\", #数据不进行排序\n",
    "        levels = [      #配置每个层级的表现形式\n",
    "            {},\n",
    "            {\n",
    "                \"r0\":\"15%\",  #内环\n",
    "                \"r\":\"35%\",   #外环\n",
    "                \"itemStyle\":{\"borderWidth\":2},#边框宽度\n",
    "                \"label\":{\"rotate\":\"tangential\"} #显示内容进行正切排序\n",
    "            },\n",
    "            {\n",
    "                \"r0\":\"35%\",\n",
    "                \"r\":\"70%\",\n",
    "                \"label\":{\"align\":\"right\"} #向右对齐\n",
    "            },\n",
    "        ],\n",
    "        )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"新冠累计确诊病例 旭日图\"))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}\")) #formatter=模板变量有 {a}, {b}，{c}，{d}，{e}，分别表示系列名，数据名，数据值等\n",
    ")\n",
    "sunburst.render_notebook()\n",
    "# render 会生成本地 HTML 文件，默认会在当前目录生成 render.html 文件\n",
    "# 也可以传入路径参数，如 \n",
    "#sunburst.render(\"sunburst.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d69a35dd-b576-48c1-a38b-c4a180d7ee66",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html>\n",
       "<html>\n",
       "<head>\n",
       "    <meta charset=\"UTF-8\">\n",
       "    <title>Awesome-pyecharts</title>\n",
       "            <script type=\"text/javascript\" src=\"https://assets.pyecharts.org/assets/echarts.min.js\"></script>\n",
       "        <script type=\"text/javascript\" src=\"https://assets.pyecharts.org/assets/themes/roma.js\"></script>\n",
       "\n",
       "</head>\n",
       "<body>\n",
       "    <div id=\"9f3729f100ef4d739216e16e7d4efd22\" class=\"chart-container\" style=\"width:1500px; height:800px;\"></div>\n",
       "    <script>\n",
       "        var chart_9f3729f100ef4d739216e16e7d4efd22 = echarts.init(\n",
       "            document.getElementById('9f3729f100ef4d739216e16e7d4efd22'), 'roma', {renderer: 'canvas'});\n",
       "        var option_9f3729f100ef4d739216e16e7d4efd22 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"treemap\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"children\": [\n",
       "                        {\n",
       "                            \"name\": \"\\u5e7f\\u5dde\",\n",
       "                            \"value\": 2762\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6df1\\u5733\",\n",
       "                            \"value\": 2511\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e1c\\u839e\",\n",
       "                            \"value\": 494\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4f5b\\u5c71\",\n",
       "                            \"value\": 368\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e2d\\u5c71\",\n",
       "                            \"value\": 123\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u73e0\\u6d77\",\n",
       "                            \"value\": 347\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6c5f\\u95e8\",\n",
       "                            \"value\": 106\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u60e0\\u5dde\",\n",
       "                            \"value\": 108\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6e5b\\u6c5f\",\n",
       "                            \"value\": 56\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u9633\\u6c5f\",\n",
       "                            \"value\": 52\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u8087\\u5e86\",\n",
       "                            \"value\": 55\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u8302\\u540d\",\n",
       "                            \"value\": 24\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e91\\u6d6e\",\n",
       "                            \"value\": 7\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6e05\\u8fdc\",\n",
       "                            \"value\": 23\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u97f6\\u5173\",\n",
       "                            \"value\": 12\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6cb3\\u6e90\",\n",
       "                            \"value\": 7\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6c55\\u5c3e\",\n",
       "                            \"value\": 13\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u63ed\\u9633\",\n",
       "                            \"value\": 11\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6c55\\u5934\",\n",
       "                            \"value\": 27\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6885\\u5dde\",\n",
       "                            \"value\": 19\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6f6e\\u5dde\",\n",
       "                            \"value\": 7\n",
       "                        }\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"children\": [\n",
       "                        {\n",
       "                            \"name\": \"\\u671d\\u9633\",\n",
       "                            \"value\": 377\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6d77\\u6dc0\",\n",
       "                            \"value\": 135\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e30\\u53f0\",\n",
       "                            \"value\": 401\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5927\\u5174\",\n",
       "                            \"value\": 157\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u623f\\u5c71\",\n",
       "                            \"value\": 151\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u77f3\\u666f\\u5c71\",\n",
       "                            \"value\": 27\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u901a\\u5dde\",\n",
       "                            \"value\": 80\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u660c\\u5e73\",\n",
       "                            \"value\": 81\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u987a\\u4e49\",\n",
       "                            \"value\": 78\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u897f\\u57ce\",\n",
       "                            \"value\": 70\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u4e1c\\u57ce\",\n",
       "                            \"value\": 49\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u95e8\\u5934\\u6c9f\",\n",
       "                            \"value\": 8\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5ef6\\u5e86\",\n",
       "                            \"value\": 2\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6000\\u67d4\",\n",
       "                            \"value\": 8\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5bc6\\u4e91\",\n",
       "                            \"value\": 9\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5e73\\u8c37\",\n",
       "                            \"value\": 0\n",
       "                        }\n",
       "                    ]\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"children\": [\n",
       "                        {\n",
       "                            \"name\": \"\\u6d66\\u4e1c\",\n",
       "                            \"value\": 16820\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u9ec4\\u6d66\",\n",
       "                            \"value\": 6222\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5f90\\u6c47\",\n",
       "                            \"value\": 4515\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u9759\\u5b89\",\n",
       "                            \"value\": 2907\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u8679\\u53e3\",\n",
       "                            \"value\": 3380\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u95f5\\u884c\",\n",
       "                            \"value\": 5259\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u6768\\u6d66\",\n",
       "                            \"value\": 1880\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5b9d\\u5c71\",\n",
       "                            \"value\": 2832\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u957f\\u5b81\",\n",
       "                            \"value\": 2377\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u666e\\u9640\",\n",
       "                            \"value\": 1737\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u9752\\u6d66\",\n",
       "                            \"value\": 1287\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5d07\\u660e\",\n",
       "                            \"value\": 383\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u677e\\u6c5f\",\n",
       "                            \"value\": 2887\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5949\\u8d24\",\n",
       "                            \"value\": 230\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u5609\\u5b9a\",\n",
       "                            \"value\": 2361\n",
       "                        },\n",
       "                        {\n",
       "                            \"name\": \"\\u91d1\\u5c71\",\n",
       "                            \"value\": 332\n",
       "                        }\n",
       "                    ]\n",
       "                }\n",
       "            ],\n",
       "            \"width\": \"80%\",\n",
       "            \"height\": \"80%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"upperlabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"drillDownIcon\": \"\\u25b6\",\n",
       "            \"roam\": true,\n",
       "            \"nodeClick\": \"zoomToNode\",\n",
       "            \"zoomToNodeRatio\": 0.1024,\n",
       "            \"levels\": [\n",
       "                {\n",
       "                    \"colorMappingBy\": \"index\",\n",
       "                    \"itemStyle\": {\n",
       "                        \"gapWidth\": 4,\n",
       "                        \"borderColor\": \"#555\",\n",
       "                        \"borderWidth\": 4\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"colorSaturation\": [\n",
       "                        0.3,\n",
       "                        0.6\n",
       "                    ],\n",
       "                    \"colorMappingBy\": \"index\",\n",
       "                    \"itemStyle\": {\n",
       "                        \"gapWidth\": 2,\n",
       "                        \"borderWidth\": 2,\n",
       "                        \"borderColorSaturation\": 0.7\n",
       "                    }\n",
       "                }\n",
       "            ],\n",
       "            \"colorMappingBy\": \"index\",\n",
       "            \"visibleMin\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u65b0\\u51a0\\u7d2f\\u8ba1\\u786e\\u8bca \\u77e9\\u5f62\\u6811\\u72b6\\u56fe\",\n",
       "            \"subtext\": \"2022/05\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "        chart_9f3729f100ef4d739216e16e7d4efd22.setOption(option_9f3729f100ef4d739216e16e7d4efd22);\n",
       "    </script>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7fcb09425eb0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 新冠累计确诊 树状图\n",
    "data = [\n",
    "    {\"name\": \"广东\",\n",
    "     \"children\": [\n",
    "             {\"name\": \"广州\", \"value\": 2762},\n",
    "             {\"name\": \"深圳\", \"value\": 2511},\n",
    "             {\"name\": \"东莞\", \"value\": 494},\n",
    "             {\"name\": \"佛山\", \"value\": 368},\n",
    "             {\"name\": \"中山\", \"value\": 123},\n",
    "             {\"name\": \"珠海\", \"value\": 347},\n",
    "             {\"name\": \"江门\", \"value\": 106},\n",
    "             {\"name\": \"惠州\", \"value\": 108},\n",
    "             {\"name\": \"湛江\", \"value\": 56},\n",
    "             {\"name\": \"阳江\", \"value\": 52},\n",
    "             {\"name\": \"肇庆\", \"value\": 55},\n",
    "             {\"name\": \"茂名\", \"value\": 24},\n",
    "             {\"name\": \"云浮\", \"value\": 7},\n",
    "             {\"name\": \"清远\", \"value\": 23},\n",
    "             {\"name\": \"韶关\", \"value\": 12},\n",
    "             {\"name\": \"河源\", \"value\": 7},\n",
    "             {\"name\": \"汕尾\", \"value\": 13},\n",
    "             {\"name\": \"揭阳\", \"value\": 11},\n",
    "             {\"name\": \"汕头\", \"value\": 27},\n",
    "             {\"name\": \"梅州\", \"value\": 19},\n",
    "             {\"name\": \"潮州\", \"value\": 7}   \n",
    "     ],\n",
    "     },\n",
    "    {\"name\": \"北京\",\n",
    "     \"children\": [\n",
    "             {\"name\": \"朝阳\", \"value\": 377},\n",
    "             {\"name\": \"海淀\", \"value\": 135},\n",
    "             {\"name\": \"丰台\", \"value\": 401},\n",
    "             {\"name\": \"大兴\", \"value\": 157},\n",
    "             {\"name\": \"房山\", \"value\": 151},\n",
    "             {\"name\": \"石景山\", \"value\": 27},\n",
    "             {\"name\": \"通州\", \"value\": 80},\n",
    "             {\"name\": \"昌平\", \"value\": 81},\n",
    "             {\"name\": \"顺义\", \"value\": 78},\n",
    "             {\"name\": \"西城\", \"value\": 70},\n",
    "             {\"name\": \"东城\", \"value\": 49},\n",
    "             {\"name\": \"门头沟\", \"value\": 8},\n",
    "             {\"name\": \"延庆\", \"value\": 2},\n",
    "             {\"name\": \"怀柔\", \"value\": 8},\n",
    "             {\"name\": \"密云\", \"value\": 9},\n",
    "             {\"name\": \"平谷\", \"value\": 0},\n",
    "     ],\n",
    "     },\n",
    "    {\"name\": \"上海\", \n",
    "     \"children\": [\n",
    "             {\"name\": \"浦东\", \"value\": 16820},\n",
    "             {\"name\": \"黄浦\", \"value\": 6222},\n",
    "             {\"name\": \"徐汇\", \"value\": 4515},\n",
    "             {\"name\": \"静安\", \"value\": 2907},\n",
    "             {\"name\": \"虹口\", \"value\": 3380},\n",
    "             {\"name\": \"闵行\", \"value\": 5259},\n",
    "             {\"name\": \"杨浦\", \"value\": 1880},\n",
    "             {\"name\": \"宝山\", \"value\": 2832},\n",
    "             {\"name\": \"长宁\", \"value\": 2377},\n",
    "             {\"name\": \"普陀\", \"value\": 1737},\n",
    "             {\"name\": \"青浦\", \"value\": 1287},\n",
    "             {\"name\": \"崇明\", \"value\": 383},\n",
    "             {\"name\": \"松江\", \"value\": 2887},\n",
    "             {\"name\": \"奉贤\", \"value\": 230},\n",
    "             {\"name\": \"嘉定\", \"value\": 2361},\n",
    "             {\"name\": \"金山\", \"value\": 332},\n",
    "     ],\n",
    "     },\n",
    "]\n",
    "\n",
    "treemap = (\n",
    "    TreeMap(init_opts = opts.InitOpts(width = \"1500px\",height = \"800px\",theme=ThemeType.ROMA))\n",
    "    .add(\n",
    "        \"\", \n",
    "        data = data,\n",
    "        levels = [\n",
    "            opts.TreeMapLevelsOpts(\n",
    "                treemap_itemstyle_opts=opts.TreeMapItemStyleOpts(\n",
    "                    border_color = \"#555\", border_width = 4, gap_width = 4\n",
    "                )\n",
    "            ),\n",
    "            opts.TreeMapLevelsOpts(\n",
    "                color_saturation = [0.3, 0.6], # 设置颜色饱和度\n",
    "                treemap_itemstyle_opts = opts.TreeMapItemStyleOpts(\n",
    "                    border_color_saturation = 0.7, gap_width = 2, border_width = 2\n",
    "                ),\n",
    "            ),\n",
    "        ],\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(\n",
    "            title = \"新冠累计确诊 矩形树状图\",\n",
    "            subtitle=\"2022/05\"\n",
    "        )\n",
    "    )\n",
    ")\n",
    "\n",
    "treemap.render_notebook()\n",
    "#treemap.render(\"treemap.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78a812e7-0e5c-43e6-aac1-7c79c9b15fc8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db68f815-fe2a-49e6-9a0e-92c56ca0deb3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b7038c4-322e-425c-a898-767e8e5c64b2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ed4934b-ceaa-4b40-866f-d86e7251510d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
